package com.toocms.jinjuhang.utils

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.LogUtils
import com.qmuiteam.qmui.arch.QMUIFragment
import com.toocms.jinjuhang.config.Constants
import com.toocms.jinjuhang.config.UserRepository
import com.toocms.jinjuhang.ui.advert_list.AdvertListFgt
import com.toocms.jinjuhang.ui.commodity.classify.ClassifyCommodityListFgt
import com.toocms.jinjuhang.ui.commodity.detils.CommodityDetailsFgt
import com.toocms.jinjuhang.ui.commodity.succour.SuccourDetailsFgt
import com.toocms.jinjuhang.ui.enterprise_windows.EnterpriseWindowsFgt
import com.toocms.jinjuhang.ui.index.article_details.ArticleDetailsFgt
import com.toocms.jinjuhang.ui.index.news.NewsFgt
import com.toocms.jinjuhang.ui.login.LoginFgt
import com.toocms.jinjuhang.ui.mine.certification.CertificationFgt
import com.toocms.jinjuhang.ui.web.WebFgt
import com.toocms.tab.base.BaseActivity

object RuleSkip {
    fun skip(rule: String?, params: String?) {
        var fgt: Fragment? = null
        val bundle = Bundle()
        when (rule) {
            "1" -> { //网址            网址
                fgt = WebFgt()
                bundle.putString(Constants.BundleKey.KEY_URL, params)
            }
            "2" -> { //资讯首页
                fgt = NewsFgt()
                bundle.putString(Constants.BundleKey.KEY_TYPE, Constants.Extra.NEWS_TYPE_NEWS)
            }
            "3" -> { //文章详情     文章ID
                fgt = ArticleDetailsFgt()
                bundle.putString(Constants.BundleKey.KEY_TYPE, Constants.Extra.NEWS_TYPE_NEWS)
                bundle.putString(Constants.BundleKey.KEY_NEWS_ID, params)
            }
            "4" -> { //专区列表      A-B   A表示专区类型 1商品 2救助 B为专区的ID
                LogUtils.e(
                    params,
                    params?.indexOf("-")
                )
                fgt = ClassifyCommodityListFgt()
                bundle.putString(
                    Constants.BundleKey.KEY_TYPE, params?.substring(0, params.indexOf("-")) ?: ""
                )
                bundle.putString(
                    Constants.BundleKey.KEY_ZONE_ID,
                    params?.substring(params.indexOf("-") + 1, params.length) ?: ""
                )
            }
            "5" -> { //商品详情      商品ID
                fgt = CommodityDetailsFgt()
                bundle.putString(Constants.BundleKey.KEY_GOODS_ID, params)
            }
            "6" -> { //救助详情      救助ID
                fgt = SuccourDetailsFgt()
                bundle.putString(Constants.BundleKey.KEY_REFUND_ID, params)
            }
            "7" -> { //资质
                fgt = CertificationFgt()
            }
            "8" -> { //活动专区
                fgt = NewsFgt()
                bundle.putString(Constants.BundleKey.KEY_TYPE, Constants.Extra.NEWS_TYPE_ACTIVE)
            }
            "9" -> { //企业视窗
                fgt = EnterpriseWindowsFgt()
            }
            "10" -> { //直播间 -----直播间id

            }
            "11" -> { //短视频
                fgt = if (UserRepository.isLogin()) AdvertListFgt() else LoginFgt()
            }
        }
        if (null == fgt) return
        fgt.arguments = bundle
        (ActivityUtils.getTopActivity() as BaseActivity).startFragment(fgt as QMUIFragment)
    }
}